package org.HisCanvas.ChrisRiffle.JFlightLog.swingUi.table;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JTable;
import javax.swing.ListSelectionModel;
import javax.swing.table.TableCellRenderer;



public class LogBookTable extends JTable{
	
	
	
	public LogBookTable() {
		
		setFillsViewportHeight(true);
	
    	setBackground(Color.WHITE);
    	
    	setForeground(Color.BLUE);
    	
    	setOpaque(true);
        
    	setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        
        setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        
        getTableHeader().setReorderingAllowed(false);//don't let user move col's
        
        getTableHeader().setResizingAllowed(true);//	
		
	}
	
	
	
	/**
	 * Overrides parent method, to alternate row-color so it's easier to follow
	 * rows with the eyes
	 */
	public Component prepareRenderer(TableCellRenderer renderer, int rowIndex,
			int vColIndex) {

		Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
		if (isCellSelected(rowIndex, vColIndex)) {
			c.setBackground(Color.BLUE);
			c.setForeground(Color.WHITE);
		} else if (rowIndex % 2 == 0) {// even # rows
			c.setBackground(Color.WHITE);
			c.setForeground(Color.BLUE);
		} else { // odd # rows
			c.setBackground(new Color(.86f, .87f, .76f));// very light gray
															// (rgb)
			c.setForeground(Color.BLUE);
		}
		return c;
	}
}
